﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SuperJoe.Framework.UnitOfWorkSql;
using WWX.MemberPortal.IDAL;
using WWX.Model;

namespace WWX.MemberPortal.DAL
{
    public class MemberDAL : BaseDAL, IMemberDAL
    {
        public MemberDAL(IUnitOfWork uow) : base(uow)
        {
        }

        public Member Get(string id)
        {
            var sql = "select * from members where id=?id";
            return this.GetModel<Member>(sql, new Dictionary<string, object>() { { "id", id } });
        }

        public Member Get(string account, string pwd)
        {
            var sql = "select * from members where account=?account and pwd=?pwd";
            return this.GetModel<Member>(sql, new Dictionary<string, object>() { { "account", account }, { "pwd", pwd } });
        }

        public void UpdatePwd(string id, string pwd)
        {
            var sql = "update members set pwd=?pwd where id=?id";
            this.Execute(sql, new Dictionary<string, object>() { { "pwd", pwd }, { "id", id } });
        }

        public void UpdateAddress(string id, string address)
        {
            var sql = "update members set address=?address where id=?id";

            this.Execute(sql, new Dictionary<string, object>() { { "address", address }, { "id", id } });
        }
    }
}
